02 / 04

How do you use pprof to profile a live Go service in production?

Register pprof HTTP handlers on an internal port, use go tool pprof to collect CPU, heap, and goroutine profiles, and visualize with flame graphs to find performance bottlenecks.

pprof setup and usage
Profiling workflow
  1. 1

    Reproduce the issue under load, then collect a 30-60 second CPU profile

  2. 2

    Flame graph: wide boxes are hot code — focus on the widest frames

  3. 3

    Heap in-use profile shows live allocations — heap allocs profile shows cumulative allocations

  4. 4

    Compare before/after with pprof diff: pprof -base before.pb.gz after.pb.gz

  5. 5

    Security: never expose pprof endpoints on public-facing ports — use internal port or VPN